package com.xnyzc.lhy.task.task.statistics;

import com.xnyzc.lhy.common.component.redis.RedisCommon;
import com.xnyzc.lhy.common.constant.RedisPrefixConstant;
import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.task.fegin.statistics.QuartzCapacityStatisticsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @Author: wangshuo
 * @Date: 2019-11-28
 * @Description 运力统计
 */

@Slf4j
@Component("quartzCapacityStatistics")
public class QuartzCapacityStatistics {

    @Autowired
    private QuartzCapacityStatisticsService quartzCapacityStatisticsService;

    @Autowired
    private RedisCommon redisCommon;


    /**
     * 保存运力统计
     * 每20分钟执行一次
     */
    @Scheduled(cron = "0 */20 * * * ?")
    public void getSaveCapacityStatistical() {
        log.info("===========开始保存运力统计==========");
        quartzCapacityStatisticsService.getSaveCapacityStatistical();
        log.info("===========结束保存运力统计===========");
    }

    /**
     * 保存出车司机统计
     * 每30分钟执行一次
     */
    @Scheduled(cron = "0 */30 * * * ?")
    public void saveCapacityStaticstical() {
        Rv result = quartzCapacityStatisticsService.saveDriveOutCount();
        if (result.getCode() != 0) {
            quartzCapacityStatisticsService.saveDriveOutCount();
        }
    }

    /**
     * 保存日活司机数量
     * 每30分钟执行一次
     */
    @Scheduled(cron = "0 00 00 * * ?")
    public void saveActiveDriver() {
        Rv result = quartzCapacityStatisticsService.saveActiveDriver();
        if (result.getCode() != 0) {
            quartzCapacityStatisticsService.saveActiveDriver();
        }
    }

    @Scheduled(cron = "0 00 00 * * ?")
    public void clearEstimateCount() {
        log.info("====================开始清除每日预估量====================");
        redisCommon.remove(RedisPrefixConstant.DIDI_ESTIMATE_NUMBER);
        log.info("====================清除结束每日预估量====================");
    }

}
